//
//  DetailsViewController.m
//  Vision
//
//  Created by dllo on 16/3/12.
//  Copyright © 2016年 yue_zhang. All rights reserved.
//

#import "DetailsViewController.h"
#import "DetailsCollectionViewCell.h"

@interface DetailsViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UIView *backView;
@property (weak, nonatomic) IBOutlet UICollectionView *backCollectionView;

- (IBAction)timeButton:(id)sender;

- (IBAction)shareButton:(id)sender;
@end

@implementation DetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self createView];
}

#pragma mark ---------- 设置页面 ----------
-(void)createView{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.minimumInteritemSpacing = 0 ;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    [self.backCollectionView setCollectionViewLayout:flowLayout];
    self.backCollectionView.backgroundColor = [UIColor whiteColor];
    [self.backCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([DetailsCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([DetailsCollectionViewCell class])];
}
#pragma mark ---------- collectionView协议方法 ----------
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 2;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DetailsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([DetailsCollectionViewCell class]) forIndexPath:indexPath];
    cell.cellID = self.detailsID;
    cell.detailsTableView.tag = 1000+indexPath.item;
    return cell;

}
#pragma mark --------- UICollectionViewDelegateFlowLayout协议方法 ---------
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(self.view.frame.size.width, self.view.frame.size.height - 104);
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark --------- timeButton的点击方法 ---------
- (IBAction)timeButton:(id)sender {
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
    [self.backCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionRight animated:YES];
}
#pragma mark --------- shareButton的点击方法 ---------
- (IBAction)shareButton:(id)sender {
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:0];
    [self.backCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
    
}
@end
